package com.thd.framework.camunda.listener;

import com.thd.framework.basic.utils.SpringUtils;
import com.thd.framework.camunda.service.WorkFlowService;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.DelegateTask;
import org.camunda.bpm.engine.delegate.ExecutionListener;
import org.camunda.bpm.engine.delegate.TaskListener;

/**
 * com.thd.springboottest.camunda.listener.ProcessInstanceListener
 *
 * @author: wanglei62
 * @DATE: 2022/6/1 8:59
 **/

public class CamundaListener implements TaskListener, ExecutionListener {
    @Override
    public void notify(DelegateExecution delegateExecution) throws Exception {
        String eventName = delegateExecution.getEventName();
        System.out.println("Execution Listener , event : " + eventName);

        if("create".equals(eventName)){
            System.out.println("create===========流程启动");
        }else if("assigment".equals(eventName)){
            System.out.println("assigment===========流程部署");
        }else if("complete".equals(eventName)){
            System.out.println("complete===========流程完成");
        }else if("delete".equals(eventName)){
            System.out.println("delete===========流程结束");
        }else if("start".equals(eventName)){
            System.out.println("start===========流程启动");
        }else if("end".equals(eventName)){
            System.out.println("end===========流程结束");
        }

        WorkFlowService workFlowService = (WorkFlowService) SpringUtils.getBean("WorkForServiceImplForCamunda");
        System.out.println(workFlowService);

        System.out.println("监听,流程实例ID：" + delegateExecution.getProcessInstanceId());

    }

    @Override
    public void notify(DelegateTask delegateTask) {
        String eventName = delegateTask.getEventName();
        System.out.println("Task Listener , event : " + eventName);
        System.out.println("监听,待办ID：" + delegateTask.getId());
        System.out.println("---- 待办KEY：" + delegateTask.getTaskDefinitionKey());
        System.out.println("---- 待办名称：" + delegateTask.getName());

    }
}
